home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / CellScrollView.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  3.0 KB  |  134 lines

  1.  
  2. static char RCSId[]="$Id: CellScrollView.m,v 1.1.1.1 1993/03/18 03:31:24 davis Exp $";
  3.  
  4.  
  5. /*
  6.  *  Based heavily on the NeXTSTEP MiniExample CellScrollView
  7.  *  by R. Dunbar Poor and Mai Nguyen.
  8.  */
  9.  
  10. #import "CellScrollView.h"
  11. #import "MultipleSelectionMatrix.h"
  12. #import "SubCell.h"
  13.  
  14.  
  15. @implementation CellScrollView
  16.  
  17. - init
  18. {
  19.     return [self initFrame:NULL];
  20. }
  21.  
  22.  
  23. /* Designated initializer */
  24. - initFrame:(const NXRect *)frameRect
  25. {
  26.   [super initFrame:frameRect];
  27.   cellMatrix = nil;
  28.  
  29.   return self;
  30. }
  31.  
  32.  
  33. - initMatrix:classId
  34. {
  35.     NXSize interCellSpacing = {0.0, 0.0}, docSize;
  36.  
  37.     /* 
  38.      *  This method should only be called once.  Check to see if 
  39.      *  cellMatrix already exists.
  40.      */
  41.     if (cellMatrix || !classId)
  42.     return nil;
  43.  
  44.     cellMatrix = [[MultipleSelectionMatrix alloc] initFrame: &frame
  45.                       mode: NX_LISTMODE
  46.                  cellClass: (cellClass = classId)
  47.                    numRows: 0
  48.                    numCols: 1];
  49.  
  50.     [cellMatrix setIntercell:&interCellSpacing];
  51.     [cellMatrix sizeToCells];        /* Resize matrix to contain cells    */
  52.     [cellMatrix setAutosizeCells:YES];
  53.  
  54.     [cellMatrix setAutoscroll:YES];    /* Auto-scroll on drag if necessary  */
  55.     [cellMatrix setAutosizing:NX_WIDTHSIZABLE];
  56.  
  57.     [[self setDocView:cellMatrix] free];
  58.  
  59.     [self setVertScrollerRequired:YES];
  60.     [self setBorderType:NX_BEZEL];
  61.     [self setAutoresizeSubviews:YES];
  62.     /* This is the only way to get the clipview to resize too */
  63.     [[cellMatrix superview] setAutoresizeSubviews:YES];
  64.  
  65.     /* Resize the matrix to fill the inside of the scrollview */
  66.     [self getContentSize:&docSize];
  67.     [cellMatrix sizeTo:docSize.width :docSize.height];
  68.  
  69.     return self;
  70. }
  71.  
  72.  
  73. - free
  74. {
  75.     if (cellMatrix)
  76.     [cellMatrix free];
  77.  
  78.     return [super free];
  79. }
  80.  
  81.  
  82. - cellMatrix
  83. {
  84.   return cellMatrix;
  85. }
  86.  
  87.  
  88. - loadCellsFrom:(List *)cellObjects
  89. /*
  90.  *  Fill the matrix with Cells, associate each Cell with a cellObject.
  91.  *
  92.  *  Since we recycle the cells (via renewRows:cols:), we also set the 
  93.  *  state of each cell to 0 and unhighlight it.  If we don't do that, 
  94.  *  the recycled cells will display their previous state.
  95.  */
  96. {
  97.   int i, cellCount;
  98.  
  99.   cellCount = [cellObjects count];
  100.  
  101.   /* tell the matrix there are 0 cells in it (but don't deallocate them) */
  102.   [cellMatrix renewRows:0 cols:1];
  103.   [cellMatrix lockFocus];               /* for highlightCellAt::lit: */
  104.   for (i=0;i<cellCount;i++) {
  105.       id cell;
  106.       /*
  107.        *  Add a row to the matrix.  (This doesn't necessarily allocate 
  108.        *  a new cell, thanks to renewRows:cols:).
  109.        */
  110.       [cellMatrix addRow];
  111.       cell = [cellMatrix cellAt:i:0];
  112.       /* make sure the cell is neither selected nor highlighted */
  113.       [cellMatrix highlightCellAt:i:0 lit:NO];
  114.       [cell setState:0];
  115.       /* install the cellObject in that cell */
  116.       [cell setSubObject:[cellObjects objectAt:i]];
  117.   }
  118.   [cellMatrix unlockFocus];
  119.   [cellMatrix sizeToCells];
  120.   [cellMatrix display];
  121.   
  122.   return self;
  123. }
  124.  
  125.  
  126. // Shuts up the compiler about unused RCSId
  127. - (const char *) rcsid
  128. {
  129.     return RCSId;
  130. }
  131.  
  132.  
  133. @end
  134.